package com.bdrm.controller.admin;

import com.bdrm.dto.OrderPageQueryDTO;
import com.bdrm.dto.OrderRejectionDTO;
import com.bdrm.dto.OrdersCancelDTO;
import com.bdrm.result.PageResult;
import com.bdrm.result.Result;
import com.bdrm.service.OrderService;
import com.bdrm.vo.OrderInfoVO;
import com.bdrm.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController("AdminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/page")
    @ApiOperation("分页查询订单列表")
    public Result<PageResult> conditionSearch(@RequestBody OrderPageQueryDTO orderPageQueryDTO) {
        log.info("分页查询订单列表，参数：{}",orderPageQueryDTO);
         PageResult page=orderService.conditionSearch(orderPageQueryDTO);
         return Result.success(page);
    }

    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO= orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        log.info("订单号：{}",id);
        orderService.completeById(id);
        return Result.success();
    }

    @ApiOperation("拒绝订单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrderRejectionDTO orderRejectionDTO){
        orderService.rejection(orderRejectionDTO);
        return Result.success();
    }

    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(Long id){
        log.info("订单号：{}",id);
        orderService.confirm(id);
        return Result.success();
    }


    @ApiOperation("查看商品详情")
    @GetMapping("/details/{id}")
    public Result<OrderInfoVO> detailsById(@PathVariable Long id){
        OrderInfoVO orderInfoVO = orderService.detailById(id);
        return Result.success(orderInfoVO);
    }

    @ApiOperation("派送")
    @PutMapping("/delivery/{id}")
    public Result deliveryById(@PathVariable Long id){
        log.info("订单号：{}",id);
        orderService.deliveryById(id);
        return Result.success();
    }
}
